package com.hongxun.design.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.PolylineOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.DistanceUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hongxun.design.MyApp;
import com.hongxun.design.R;
import com.hongxun.design.acceptance.activity.AcceptActivity;
import com.hongxun.design.adapters.SetPointInformationAdapter;
import com.hongxun.design.bean.AddExplorationBean;
import com.hongxun.design.bean.BitTypeTabItemBean;
import com.hongxun.design.bean.CodeSetBean;
import com.hongxun.design.bean.Exploration;
import com.hongxun.design.bean.SetPointInfItemBean;
import com.hongxun.design.bean.SpanBean;
import com.hongxun.design.bean.photopassbean.SystemTypeBean;
import com.hongxun.design.constant.Constant;
import com.hongxun.design.interfaces.HeadSecond;
import com.hongxun.design.jungong.activity.BjListActivity;
import com.hongxun.design.listeners.ListenerSet;
import com.hongxun.design.mytools.CheckClickTime;
import com.hongxun.design.mytools.IconSourse;
import com.hongxun.design.mytools.IntentToActivity;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.mytools.SetTypeface;
import com.hongxun.design.mytools.ShardPreferencesTool;
import com.hongxun.design.mytools.ToastShow;
import com.hongxun.design.object_properties.MyMessage;
import com.hongxun.design.sqlite.bean.PointLaXian;
import com.hongxun.design.ui.MBaiduMap;
import com.hongxun.design.ui.dialogstyle.LoadingDialog;
import com.hongxun.design.ui.dialogstyle.MyDialog;
import com.hongxun.design.ui.headandbottonpanel.HeadSecondControlPanel;
import com.hongxun.design.utils.DataUtil;
import com.hongxun.design.utils.PopwindowUtil;
import com.hongxun.design.utils.StringUtil;
import com.hongxun.design.utils.fastjson.FastJsonUtil;
import com.hongxun.design.utils.fileutil.GetFileUtil;
import com.hongxun.design.utils.fileutil.SetFileUtil;
import com.hongxun.design.utils.httputil.HttpStringCodeTableUtil;
import com.hongxun.design.utils.httputil.HttpStringUtil;
import com.hongxun.design.utils.httputil.PostParams;
import com.hongxun.design.utils.imageutil.UriUtil;
import com.hongxun.design.utils.projectdatautil.DataFactory;
import com.hongxun.design.utils.projectdatautil.PointPaizi;
import com.pop.android.common.util.ToastUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by zerdoor_pc on 2016/5/9.
 * 点位信息设置界面
 */
public class SetPointInformationActivity extends BaseActivity implements HeadSecond {
    public MapView mMapView;
    public BaiduMap mBaiduMap;
    public MBaiduMap baidumapstyle;
    public static LatLng currentPt;//选定的点位
    private Handler finishHandler;
    private Handler ContinueHandler;
    private Handler pointHandler;
    private Handler lineTypeHandler;
    private Handler explorationHandler;
    private Handler updateHandler;
    public Handler cornerHandler;
    public Handler handler;
    String NUMBER = "N0";
    public static String type = MString.code_null;
    ArrayList<SystemTypeBean> before_expData;
    List<Exploration> data;
    List<SystemTypeBean> Wire;//导线型号
    TextView setpoint_type;
    TextView setpoint_ys;//验收
    ListView setpoint_attribute;
    public static SetPointInformationAdapter adapter;
    List<SetPointInfItemBean> list;
    public static String name;
    public View map_style;
    private Handler getNewNumHandler;
    String exploration_id = "", exploration_uuid = "";

    @Override
    protected void onDestroy() {
        adapter = null;
        list = null;
        ContinueHandler = null;
        data = null;
        name = null;
        currentPt = null;
        MyApp.codeSetBean = null;
        if (baidumapstyle != null) baidumapstyle.onDestroy();
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        if (baidumapstyle != null) baidumapstyle.onPause();
        super.onPause();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setpointinformation);
        MyApp.voltage_grade = "";
        type = MString.code_null;
        MyApp.codeSetBean = null;
        ChoiceData = null;
        if (!MyApp.isNewAdd) {
            isNewAdd = false;
            MyApp.isNewAdd = true;
        }
        exploration_id = MyApp.currExploration.getExploration_id();
        exploration_uuid = MyApp.currExploration.getUuid();
        if (MyApp.currExploration.getPoint_type().equals(MString.NEW)) {
            MyApp.currExploration.setExploration_type(MString.NEW);
            buldeflag = true;
        } else {
            MyApp.currExploration.setExploration_type(MString.OLD);
            buldeflag = false;
        }
        if ((exploration_id.length() > 0 && !exploration_id.equals(MString.code_one)) || (exploration_uuid.length() > 0 && !exploration_uuid.equals(MString.code_one))) {
            type = "1";
        } else {
            type = MString.code_zero;
        }
        addLastHandler();
        getDate();
        findBar();
        findView();
        initialization();
    }

    /**
     * 共杆状况下获取数据*
     */
    public void gethandler() {
        addLatLngHandler();
        if (MyApp.isOnLine) {
            MyApp.HTTP.getLatLng(handler, HttpStringUtil.SUCCESSED, MyApp.currExploration.getPoint_type(), MyApp.currProject.getStage_id());
        } else {
            if (point != null && point.size() > 0) {
                List<Exploration> pointList = new ArrayList<>();
                ChoiceData = new ArrayList<>();
                if (pointList == null) return;
                for (Exploration e : point) {
                    if (e.getVoltage_grade().equals("101") && e.getPt_id().equals(MString.ganta)) {
                        pointList.add(e);
                    }
                }
                for (Exploration e : pointList) {
                    ChoiceData.add(new SystemTypeBean(e.exploration_id, e.name + "(" + e.number + ")", e.lat, e.lng));
                }
            }
        }
    }

    public static ArrayList<SystemTypeBean> ChoiceData;

    private void addLatLngHandler() {
        if (handler == null) handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            List<Exploration> pointList = FastJsonUtil.JsonToGetExplorationList((String) msg.obj);
                            ChoiceData = new ArrayList<>();
                            if (pointList == null) return;
                            for (Exploration e : pointList) {
                                ChoiceData.add(new SystemTypeBean(e.exploration_id, e.name + "(" + e.number + ")", e.lat, e.lng));
                            }
                        } else {
                            ToastShow.showShort(mActivity, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                        }
                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(mActivity, (String) msg.obj);
                        break;

                }

                super.handleMessage(msg);

            }
        };
    }

    public void getDate() {
        currentPt = new LatLng(MyApp.currExploration.getLat_d(), MyApp.currExploration.getLng_d());
        name = MyApp.currExploration.getName();
    }

    @Override
    public void findBar() {
        final HeadSecondControlPanel headsecond_layout = (HeadSecondControlPanel) findViewById(R.id.setpoint_layout);
        headsecond_layout.initHeadPanel(DataUtil.getsecondbean(IconSourse.More + "",
                View.VISIBLE, R.color.bar_right, ListenerSet.back,
                MString.SetPoint, R.color.title, View.VISIBLE, IconSourse.BACK + "", View.VISIBLE));
        headsecond_layout.setClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (exploration_id.length() == 0 && exploration_uuid.length() == 0) {
                    ToastShow.showShort(mActivity, "新增踏勘点不允许进行此操作！");
                } else {
                    PopwindowUtil.openPop(headsecond_layout.mRightTitle, mActivity, DataUtil.getPointInfPopItem());
                }

            }
        });
        if (MyApp.ReadOnly) {
            headsecond_layout.mRightTitle.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    protected void findView() {
        findViewAndInit_MapButton();//初始化地图位置
        TextView finish_button = (TextView) findViewById(R.id.setpoint_finish_button);
        TextView continue_button = (TextView) findViewById(R.id.setpoint_continue_button);
        SetTypeface.set(finish_button, IconSourse.SURE);
        finish_button.append(" 直接完成");
        continue_button.append("复核拍照 ");
        if (MyApp.ReadOnly) {
            finish_button.setBackgroundResource(R.drawable.gray_item_6);
        }
        SetTypeface.setAppend(continue_button, IconSourse.RIGHTCHOICE);
        //属性listView
        setpoint_type = (TextView) findViewById(R.id.setpoint_type);
        setpoint_type.setText(name);
        //仅点位可以验收，特征点暂不验收
        setpoint_ys = (TextView) findViewById(R.id.setpoint_ys);
        // TODO: 验收记录入口(仅点位可验收)
//        setpoint_ys.setVisibility(View.GONE);
        if (MyApp.currExploration.getPoint_type().equals("11")) {
            setpoint_ys.setVisibility(View.VISIBLE);
        } else {
            setpoint_ys.setVisibility(View.GONE);
        }
        setpoint_attribute = (ListView) findViewById(R.id.setpoint_attribute);
        super.findView();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 9 && data != null) {
            String code = data.getStringExtra("result");
            adapter.setScanCode(code);
        }
    }

    @Override
    protected void initialization() {
        currtlat = -1;
        currtlon = -1;
        //转角与拍直
        addCornerHandler();
        addLineTypeHandler();
        addPointHandler();
        addexplorationHandler();//加载踏勘点信息接收器

        //获取导线型号
        String pointJson = ShardPreferencesTool.getshare(this, HttpStringCodeTableUtil.WireList, "");

        if (pointJson != null && pointJson.length() > 0) {
            if (Wire == null) {
                Wire = new ArrayList<>();
            } else {
                Wire.clear();
            }
            Wire.addAll(FastJsonUtil.JsonToGetWireList(pointJson));

            lineTypeHandler.sendEmptyMessage(1);
        } else {
            getWireList();//获取导线类型
        }
        if (list == null) {
            list = getListData();
        }
        //加载栏目
        if (adapter == null) {
            adapter = new SetPointInformationAdapter(list, this);
            setpoint_attribute.setAdapter(adapter);
        }


        super.initialization();
    }

    /**
     * ********************************网络请求*************************************************************************
     */

    /**
     * 获取导线型号数据*
     */
    private void getWireList() {
        if (MyApp.isOnLine) {
            MyApp.HTTP.getWireList(lineTypeHandler, HttpStringUtil.SUCCESSED);
        } else {
            String pointJson = ShardPreferencesTool.getshare(this, HttpStringCodeTableUtil.WireList, "");
            if (pointJson != null && pointJson.length() > 0) {
                if (Wire == null) {
                    Wire = new ArrayList<>();
                } else {
                    Wire.clear();
                }
                Wire.addAll(FastJsonUtil.JsonToGetWireList(pointJson));

            }
            if (Wire == null) Wire = new ArrayList<>();
            lineTypeHandler.sendEmptyMessage(1);
        }
    }

    /**
     * 获取点位列表并加载数据*
     */
    private void getExplorationList() {
        if (MyApp.isOnLine) {
            MyApp.HTTP.getExplorationList(pointHandler, HttpStringUtil.SUCCESSED, projectType,
                    MyApp.currProject.getStage_id(), "");//获取踏勘点列表
        } else {
            if (data == null) {
                data = GetFileUtil.getExplorationList(projectType);
            } else {
                data.clear();
                data.addAll(GetFileUtil.getExplorationList(projectType));
            }
            pointHandler.sendEmptyMessage(4);
        }

    }


    /**
     * 获取点位信息*
     */
    private void getExplorationInfo(Exploration e) {
        if (MyApp.isOnLine) {
            MyApp.HTTP.getExploration(explorationHandler, HttpStringUtil.SUCCESSED, e.exploration_id);//获取踏勘点信息(第二次进入)
        } else {
            String s = GetFileUtil.getExplorationInfo(e);
            explorationHandler.sendMessage(MyMessage.getMessage(HttpStringUtil.SUCCESSED, s));
        }
    }
    /***********************************创建项目原始数据创建**************************************************************************/
    /**
     * 创建项目条目数据*
     */
    private List<SetPointInfItemBean> getListData() {
        if (name == null || name.length() == 0) return new ArrayList<>();
        List<SetPointInfItemBean> data = new ArrayList<>();
        setBase(data);
        switch (name) {
            case Constant.搭火点:
                data.add(new SetPointInfItemBean("搭火名称", MString.name, Constant.EdStyle, "填写", "", true, null));//10kV大花路13#杆/XX变电站4#间隔
                data.add(new SetPointInfItemBean("接线方式", MString.wiring_way, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.wiringWay)));//T接/间隔
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                break;
            case Constant.柱上变压器:
                data.add(new SetPointInfItemBean("设备名称", MString.name, Constant.EdStyle, "填写", "", true, null));
                data.add(new SetPointInfItemBean("设备属性", MString.trans_attribute, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.transAttribute)));//新建/利旧
                data.add(new SetPointInfItemBean("设备容量", MString.trans_capacity, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.transCapacity)));
                data.add(new SetPointInfItemBean("设备型号", MString.trans_type, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.transType)));
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));
                break;
            case Constant.箱式变电站:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));
                break;
            case Constant.杆塔:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));//10kV/0.38kV/0.22kV
                data.add(new SetPointInfItemBean("新建/利旧", MString.pole_attribute, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.poleAttribute)));
//                data.add(new SetPointInfItemBean("是否共杆", MString.is_common, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getArrayList(MString.YES_, MString.NO_)));//
                data.add(new SetPointInfItemBean("塔杆类型", MString.pole_type, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.poleType)));
                data.add(new SetPointInfItemBean("杆塔高度", MString.height, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.poleHeight)));
//                data.add(new SetPointInfItemBean("杆型材料", MString.pole_material, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.poleMaterial)));
//                data.add(new SetPointInfItemBean("导线类型", MString.wire_type, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.wireType)));
                data.add(new SetPointInfItemBean("导线型号", MString.wire_model, Constant.ChoiceStyle, "未选择", "", true, (ArrayList<SystemTypeBean>) Wire));
                data.add(new SetPointInfItemBean("导线回数", MString.wire_times, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.highWireTimes)));
                data.add(new SetPointInfItemBean("杆塔拉线数", MString.laxian, Constant.EdStyle, "0", "0", false, null, InputType.TYPE_CLASS_NUMBER));
//                data.add(new SetPointInfItemBean("杆上设备", MString.pole_device, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.poleDevice)));
                break;
            case Constant.下户点:
                data.add(new SetPointInfItemBean("下户名", MString.user_name, Constant.ActivityStyle, "选择", "", true, null));
                data.add(new SetPointInfItemBean(false, "下户数", MString.user_num, Constant.EdStyle, "-", "", true, null));
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.户表箱:
                data.add(new SetPointInfItemBean("下户点", MString.user_point, Constant.EdStyle, "填写", "", true, null));
                data.add(new SetPointInfItemBean("表箱位数", MString.digit, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.digit)));
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                data.add(new SetPointInfItemBean("旧条形码", MString.bx_old_code, Constant.ScanStyle, "", "", false, null));
                data.add(new SetPointInfItemBean("新条形码", MString.bx_new_code, Constant.ScanStyle, "", "", true, null));
                data.add(new SetPointInfItemBean("用户表计", MString.bx_bj_code, Constant.ScanStyle, "", "", false, null));
//                data.add(new SetPointInfItemBean("采集器编号", MString.bx_cjq_code, Constant.EdStyle, "填写", "1", false, null));
                data.add(new SetPointInfItemBean(true, "采集器编号", MString.bx_cjq_code, Constant.EdStyle, "填写", "", false, null));
                data.add(new SetPointInfItemBean("IP地址", MString.bx_ip_address, Constant.EdStyle, "填写", "", false, null));
                data.add(new SetPointInfItemBean("安装位置", MString.bx_address, Constant.EdStyle, "填写", "", false, null));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设的编号（名称）选择
                break;
            case Constant.环网柜:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.电缆分支箱:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.开关站:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.配电室:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.沿墙电缆:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.通道电缆:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.电缆井:
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                // data.add(new SetPointInfItemBean("典设方案", null, Constant.JumpStyle, "未选择", "", false, null));//典设编号（名称）
                break;
            case Constant.植被:
                data.add(new SetPointInfItemBean("类型", MString.vegetation_type, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.vegetationType)));
                data.add(new SetPointInfItemBean("高度", MString.height, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("角度", MString.angle, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("与被跨越物水平距离", MString.horizon_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("砍青数", MString.fell_num, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                break;
            case Constant.房屋:
                data.add(new SetPointInfItemBean("房宽", MString.width, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("高度", MString.height, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("与被跨越物水平距离", MString.horizon_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("跨越角度（垂直于线路的小角度）", MString.angle, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                break;
            case Constant.通讯线:
                data.add(new SetPointInfItemBean("线高", MString.height, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("跨越角度", MString.angle, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("与被跨越物水平距离", MString.horizon_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                break;
            case Constant.低压线路:
                data.add(new SetPointInfItemBean("线高", MString.height, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("跨越角度", MString.angle, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("与被跨越物水平距离", MString.horizon_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                break;
            case Constant.沟河流:
                data.add(new SetPointInfItemBean("宽度", MString.width, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("电杆与沟（岸）边水平距离", MString.horizon_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("电杆与沟（岸）边相对高差", MString.relative_height, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("水面与岸边垂直距离", MString.vertical_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                break;
            case Constant.道路:
                data.add(new SetPointInfItemBean("类型", MString.road_type, Constant.ChoiceStyle, "未选择", "", true, DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.transportType)));
                data.add(new SetPointInfItemBean("宽度", MString.width, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("杆位与道路的水平距离", MString.horizon_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("杆位与路基高差", MString.dispersion, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));

                break;
            case Constant.高压线路:
                data.add(new SetPointInfItemBean("线高", MString.height, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("跨越角度", MString.angle, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("跨越点高程（差）", MString.dispersion, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("与被跨越物水平距离", MString.horizon_distance, Constant.EdStyle, "填写", "", false, null, InputType.TYPE_CLASS_NUMBER));
                data.add(new SetPointInfItemBean("电压等级", MString.voltage_grade, Constant.ChoiceStyle, "未选择", "", true,
                        DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.voltageGrade)));
                break;


        }
        return data;
    }

    /**
     * 创建项目条目通用数据*
     */
    private void setBase(List<SetPointInfItemBean> data) {
        if (currentPt == null) {
            data.add(new SetPointInfItemBean(0, 0, "", name, Constant.LatStyle, "", ""));
        } else {
            data.add(new SetPointInfItemBean(currentPt.latitude, currentPt.longitude,
                    MyApp.currExploration.getAlt(), name,
                    Constant.LatStyle, "", ""));
            currtlat = currentPt.latitude;
            currtlon = currentPt.longitude;
        }
        data.add(new SetPointInfItemBean(false, "编号", MString.number, Constant.dialogstyle, "填写", NUMBER, true, null));
        if (before_expData != null) {
            if (!(MyApp.currExploration.getPt_id().equals(MString.dahuodian) || pt_id.equals(MString.dahuodian))) {
                if (MyApp.isDistance) {
                    MyApp.isDistance = false;
                    data.add(new SetPointInfItemBean("上联编号", MString.before_exp, Constant.ChoiceStyle, "", MyApp.distanceName, MyApp.distanceCode, false, before_expData));
                } else {
                    data.add(new SetPointInfItemBean("上联编号", MString.before_exp, Constant.ChoiceStyle, "", before_exp, before_exp_id, false, before_expData));
                }
                //增加档距显示
                if (isaddbeforedata && before_expData.size() > 1) {
                    double lat_bef = Double.valueOf(before_expData.get(1).data.getLat());
                    double lng_bef = Double.valueOf(before_expData.get(1).data.getLng());
                    LatLng latLng_bef = new LatLng(lat_bef, lng_bef);
                    double lat_cur = Double.valueOf(MyApp.currExploration.getLat());
                    double lng_cur = Double.valueOf(MyApp.currExploration.getLng());
                    LatLng latLng_cur = new LatLng(lat_cur, lng_cur);
                    //档距按最长的来算
                    double distance = DistanceUtil.getDistance(latLng_bef, latLng_cur);
                    BigDecimal decimal = new BigDecimal(distance);
                    String dis = decimal.setScale(2, BigDecimal.ROUND_HALF_UP) + "";
                    String disCurr = MyApp.currExploration.getDistance();
                    if (TextUtils.isEmpty(disCurr)) {
                        MyApp.currExploration.setDistance(dis);
                    }
                }
                data.add(new SetPointInfItemBean(true, "档距", MString.span, Constant.EdStyle, "填写", MyApp.currExploration.getDistance(), false, null));
            }
            if (MyApp.currExploration.getPt_type().equals(Constant.LOCALPOINT) && !(!type.equals("0") && !MyApp.isOnLine)) {//过滤离线再次编辑时的角度不显示

                data.add(new SetPointInfItemBean("角度", MString.corner, Constant.ButtonStyle, "", "", false, null));
            }
        }
    }

    String before_exp = "";//上联编号
    public String before_exp_id = "";//上联ID

    public LatLng currtLatLng = null;
    public LatLng currtbeforeLatLng = null;
    public LatLng currtbeforesbeforeLatLng = null;

    public boolean paiziFlag = false;

    public LatLng getLatLng() {
        currtLatLng = null;
        currtLatLng = new LatLng(list.get(0).getLat(), list.get(0).getLon());
        return currtLatLng;
    }

    public void setBefore_exp_id(String before_exp, String before_exp_id) {
        this.before_exp = before_exp;
        this.before_exp_id = before_exp_id;
    }

    public void getPaizi() {
        //获取上联经纬
        //获取上联的上联经纬
        paiziFlag = false;
        if (currtLatLng == null) {
            getLatLng();
        }
        currtbeforeLatLng = null;
        currtbeforesbeforeLatLng = null;
        if (before_exp.length() == 0 || before_exp_id.length() == 0) {
            paiziFlag = false;
            return;
        }
        for (SystemTypeBean e : before_expData) {
            if (e.getTypecode().equals(before_exp_id) && e.getTypename().equals(before_exp) && e.data != null) {
                currtbeforeLatLng = new LatLng(e.data.getLat_d(), e.data.getLng_d());
                if (e.data.getBefore_lat() != null && e.data.getBefore_lat().length() > 0 && e.data.getBefore_lng() != null && e.data.getBefore_lng().length() > 0) {
                    currtbeforesbeforeLatLng = new LatLng(Double.parseDouble(e.data.getBefore_lat()), Double.parseDouble(e.data.getBefore_lng()));
                }
            }
        }

        if (currtbeforeLatLng != null && currtbeforesbeforeLatLng != null) {
            paiziFlag = true;
        }
        if (!type.equals("0")) {
            paiziFlag = false;
        }
        if (adapter != null) adapter.notifyDataSetChanged();
    }

    public void getPaiziClick() {
        if (currtLatLng != null && currtbeforeLatLng != null && currtbeforesbeforeLatLng != null) {
            Map<String, Object> map = PointPaizi.exp_obj(currtLatLng, currtbeforeLatLng, currtbeforesbeforeLatLng);
            double lat = (double) map.get("lat");
            double lon = (double) map.get("lng");
            int i = 0;
            for (SetPointInfItemBean s : list) {
                if (s.getNameCode() == null && Constant.LatStyle == s.getItemStyle()) {
                    s.setLat(lat);
                    s.setLon(lon);
                    i++;
                } else if (s.getNameCode() != null && s.getNameCode().equals(MString.corner) && Constant.ButtonStyle == s.getItemStyle()) {
                    s.setValue("0");
                    s.setValueCode("0");
                    paiziFlag = false;
                    i++;
                }
                if (i == 2) {
                    break;
                }
            }
            currentPt = new LatLng(lat, lon);
            addPoint();
            adapter.notifyDataSetChanged();
        }
    }


    /**
     * 转角与排直Handler*
     */
    private void addCornerHandler() {
        cornerHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            String corner = JSON.parseObject((String) msg.obj).getString("corner");
                            if (corner == null) {
                                corner = "";
                            }
                            for (SetPointInfItemBean s : list) {
                                if (s.getNameCode() != null && s.getNameCode().equals(MString.corner) && Constant.ButtonStyle == s.getItemStyle()) {
                                    s.setValue(corner);
                                    s.setValueCode(corner);
                                }
                            }
                            adapter.notifyDataSetChanged();
                        } else {
                            ToastShow.showShort(mActivity, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                        }
                        break;
                    case 2:
                        for (SetPointInfItemBean s : list) {
                            if (s.getNameCode() != null && s.getNameCode().equals(MString.corner) && Constant.ButtonStyle == s.getItemStyle()) {
                                s.setValue("");
                                s.setValueCode("");
                            }
                        }
                        paiziFlag = false;
                        adapter.notifyDataSetChanged();
                        break;
                    case 1:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            JSONObject exp_obj_up = JSON.parseObject((String) msg.obj).getJSONObject("exp_obj_up");
                            double lat = exp_obj_up.getDouble("lat");
                            double lon = exp_obj_up.getDouble("lng");
                            int i = 0;
                            for (SetPointInfItemBean s : list) {
                                if (s.getNameCode() == null && Constant.LatStyle == s.getItemStyle()) {
                                    s.setLat(lat);
                                    s.setLon(lon);
                                    i++;
                                } else if (s.getNameCode() != null && s.getNameCode().equals(MString.corner) && Constant.ButtonStyle == s.getItemStyle()) {
                                    s.setValue("0");
                                    s.setValueCode("0");
                                    i++;
                                }
                                if (i == 2) {
                                    break;
                                }
                            }
                            currentPt = new LatLng(lat, lon);
                            addPoint();
                            adapter.notifyDataSetChanged();
                        } else {
                            ToastShow.showShort(mActivity, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                        }
                        break;
                    case 3://选择上联后更新档距
                        ToastUtils.showToast(SetPointInformationActivity.this, "档距已重新获取，请手动修改");
                        String dis = "0";
                        if (msg.arg1 != 0) {
                            double lat_bef = Double.valueOf(before_expData.get(msg.arg1).data.getLat());
                            double lng_bef = Double.valueOf(before_expData.get(msg.arg1).data.getLng());
                            LatLng latLng = new LatLng(lat_bef, lng_bef);
                            //档距按最长的来算
                            double distance = DistanceUtil.getDistance(latLng, currtLatLng);
                            BigDecimal decimal = new BigDecimal(distance);
                            dis = decimal.setScale(2, BigDecimal.ROUND_HALF_UP) + "";
                            MyApp.currExploration.setDistance(dis);
                        } else {
                            MyApp.currExploration.setDistance("0");
                        }
                        for (SetPointInfItemBean itemBean : list) {
                            if (itemBean.getName().equals("档距")) {
                                itemBean.setValue(dis);
                                break;
                            }
                        }
                        adapter.notifyDataSetChanged();
                        break;
                }
                super.handleMessage(msg);
            }
        };
    }
    /***********************************下方按钮方法**************************************************************************/


    /**
     * 直接完成*
     */
    LoadingDialog loadingDialog;

    public void setFinish(View view) {
        setFinishHttp();
    }

    private void setFinishHttp() {
        if (CheckClickTime.back(this)) {
            iscontinue = false;
            if (!MyApp.ReadOnly) {
                if (!checkDateEmpty(0)) {
                    return;
                }
                if (type.equals(MString.code_zero)) {
                    updateSaveNumber();
                    addFinishHandler();
                    if (MyApp.isOnLine) {
                        showDialog();
                        String exploration_id1 = MyApp.currExploration.getExploration_id();
                        if (TextUtils.isEmpty(exploration_id1)) {
                            MyApp.HTTP.setExploration(finishHandler, HttpStringUtil.SUCCESSED, MyApp.currProject.getStage_id(), list, point);
                        } else {
                            updateData();
                        }
                    } else {
                        if (setOnLineAdd()) {
                            onBackPressed();
                            MyApp.activity.finish();
                        }
                    }
                } else {
                    updateData();
                }
            }
        }
    }

    //验收记录
    public void setAccept(View view) {
        String exploration_id1 = MyApp.currExploration.getExploration_id();
        if (TextUtils.isEmpty(exploration_id1)) {
            if (CheckClickTime.back(this)) {
                if (checkDateEmpty(0)) {
                    updateSaveNumber();
                    addFinishHandler();
                    iscontinue = true;
                    showDialog();
                    MyApp.HTTP.setExploration(finishHandler, 1, MyApp.currProject.getStage_id(), list, point);
                }
            }
        } else {
            intent2ys();
        }
    }

    //判断数据是否录入0:直接完成/验收，1继续设计
    private boolean checkDateEmpty(int dex) {
        if (dex == 0) {
            try {
                if (list.get(0).getLat() < 0 || list.get(0).getLon() < 0 || list.get(0).getLat() == 4.9E-324 || list.get(0).getLon() == 4.9E-324) {
                    ToastShow.showShort(this, "定位异常！");
                    return false;
                }
            } catch (Exception e) {
                ToastShow.showShort(this, "定位异常！");
                return false;
            }
        }
        for (SetPointInfItemBean s : list) {
            if (s.getItemStyle() == Constant.LatStyle) {
                if ((s.getLat() == 0 || s.getLat() == -1) || s.getLon() == 0 || s.getLon() == -1) {
                    ToastShow.showShort(MyApp.activity, "无效的地理位置！");
                    return false;
                }
            } else if (s.isNotNull()) {
                switch (s.getItemStyle()) {
                    case Constant.EdStyle:
                        if (!(s.getValue() != null && s.getValue().length() > 0)) {
                            ToastShow.showShort(MyApp.activity, s.getName() + "值不能为空！");
                            return false;
                        }
                        break;
                    case Constant.ChoiceStyle:
                        if (!(s.getValueCode() != null && s.getValueCode().length() > 0)) {
                            ToastShow.showShort(MyApp.activity, s.getName() + "值不能为空！");
                            return false;
                        }
                        break;
                    default:
                        if (!((s.getValue() != null && s.getValue().length() > 0)
                                || (s.getValueCode() != null && s.getValueCode().length() > 0))) {
                            ToastShow.showShort(MyApp.activity, s.getName() + "值不能为空！");
                            return false;
                        }
                        break;
                }
            }
        }
        return true;
    }

    //直接进入验收界面
    private void intent2ys() {
        String name = "";
        for (SetPointInfItemBean bean : list) {
            if (!TextUtils.isEmpty(bean.getName())) {
                if (bean.getName().equals("编号")) {
                    name = bean.getValue();
                    break;
                }
            }
        }
        Intent intent = new Intent(this, AcceptActivity.class);
        intent.putExtra("0", name);
        startActivity(intent);
    }


    private void showDialog() {
        if (loadingDialog == null) loadingDialog = new LoadingDialog(this);
        if (!loadingDialog.isShowing()) {
            loadingDialog.setText("正在处理...");
            loadingDialog.show();
        }
    }


    private void closeDialog() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }

    boolean iscontinue = false;

    //复核拍照
    public void setContinue(View view) {
        if (CheckClickTime.back(this)) {
            addContinueHandler();
            if (pt_id.length() > 0 && MyApp.currExploration.getPt_type().equals(Constant.LOCALPOINT)) {
                MyApp.setPointList.clear();
                MyApp.setPointList.addAll(list);
                MyApp.currExploration.setApapterStates(adapter.states);
                PopwindowUtil.openSetPointPopBottom(view, this, ContinueHandler);//msg:1,2
            } else {
                if (MyApp.currExploration.getPt_type().length() == 0) {
                    MyApp.currExploration.setPt_type(Constant.TEZHENGPOINT);
                }
                iscontinue = true;
                tag = 2;
                if (!MyApp.ReadOnly) {
                    choiceHttp();
                } else {
                    ContinueHandler.sendEmptyMessage(4);
                }
            }
        }
    }

    //判断拉线数是否与实际数量相同
    private boolean isSameCount() {
        boolean isSame = false, haslaxian = false;
        String laxian = ShardPreferencesTool.read(getApplicationContext(), MyApp.currExploration.getExploration_id(), "", 2);
        List<PointLaXian> laXians = JSON.parseArray(laxian, PointLaXian.class);
        for (SetPointInfItemBean bean : list) {
            if (bean.getNameCode().equals(MString.laxian)) {
                haslaxian = true;
                break;
            }
        }
        if (haslaxian) {
            for (SetPointInfItemBean bean : list) {
                if (bean.getNameCode().equals(MString.laxian)) {
                    if (bean.getValue().equals(String.valueOf(laXians.size()))) {
                        isSame = true;
                    }
                    break;
                }
            }
        } else {
            isSame = true;
        }
        return isSame;
    }

    /**
     * 数据请求判断*
     */
    public void choiceHttp() {
        if (ContinueHandler == null) addContinueHandler();
        if (exploration_id.length() == 0 && exploration_uuid.length() == 0) {
            //新增
            addData();
        } else {
            //修改
            updateData();
        }
    }

    /**
     * 修改踏勘点信息*
     */
    private void updateData() {
        addUpdateHandler();
        if (!checkDateEmpty(1)) {
            return;
        }
        if (MyApp.isOnLine) {
            MyApp.HTTP.setExplorationList(updateHandler, HttpStringUtil.SUCCESSED, list, pt_id, point);//获取踏勘点列表
        } else {
            if (setOnLineUpdate()) {
                updateHandler.sendEmptyMessage(1);
            }
        }

    }

    /**
     * 点位设置*
     */
    public void addData() {
        updateSaveNumber();
        if (!checkDateEmpty(1)) {
            return;
        }
        if (MyApp.isOnLine) {
            showDialog();
            MyApp.HTTP.setExploration(ContinueHandler, HttpStringUtil.SUCCESSED, MyApp.currProject.getStage_id(), list, point);
        } else {
            if (setOnLineAdd()) {
                ContinueHandler.sendEmptyMessage(4);
            }

        }
    }

    /***********************************网络请求接收器**************************************************************************/
    /**
     * 导线型号接收器*
     */
    private void addLineTypeHandler() {
        lineTypeHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {

                            if (Wire == null) {
                                Wire = new ArrayList<>();
                            } else {
                                Wire.clear();
                            }
                            Wire.addAll(FastJsonUtil.JsonToGetWireList(String.valueOf(msg.obj)));
                            ShardPreferencesTool.saveshare(mActivity, HttpStringCodeTableUtil.WireList, (String) msg.obj);
                            MyLog.L(MString.SUCCESSED + JSON.toJSONString(Wire));
                        } else {
                            ToastShow.showShort(mActivity, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                        }
                        lineTypeHandler.sendEmptyMessage(1);
                        break;
                    case 1:
                        isnewlyBuild(null);
                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(mActivity, msg.obj + ",导线型号获取失败!");
                        break;

                }
            }
        };
    }

    /**
     * 点位信息接收器*
     */
    String pt_id = "";

    private void addexplorationHandler() {
        explorationHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            if (!type.equals("0") && MyApp.isOnLine) {
                                SetFileUtil.setExplorationInfo((String) msg.obj);
                                //  MyApp.File.SaveFileData(MyApp.currProject.getStage_id(), MString.ProjectExplorePointInfo + "_" + exploration_id, (String) msg.obj, "no");//存储
                            }
                            MyLog.L(MString.SUCCESSED + "解析start:" + msg.obj);
                            if (JSON.parseObject((String) msg.obj).size() > 0) {
                                MyApp.currExploration.setJsonstring(msg.obj + "");
                                JSONObject jsonObject = JSON.parseObject((String) msg.obj);
                                JSONObject pt = JSON.parseObject(jsonObject.getString(MString.pt));
                                if (list == null) {
                                    list = getListData();
                                }
                                if (!type.equals("0")) {
                                    pt_id = jsonObject.getString(MString.pt_id);
                                    String uuid = jsonObject.getString(MString.uuid);
                                    MyApp.currExploration.setPt_id(pt_id);
                                    if (uuid != null) MyApp.currExploration.setUuid(uuid);
                                }
                                if (list.size() == 0) {//加载点位名称
                                    List<BitTypeTabItemBean> beans = DataUtil.getBitTypeData(1);
                                    beans.addAll(DataUtil.getBitTypeData(0));
                                    for (BitTypeTabItemBean b : beans) {
                                        if (b.getId().equals(pt_id)) {
                                            name = b.getName();
                                            MyApp.currExploration.setName(name);
                                            setpoint_type.setText(name);
                                            break;
                                        }
                                    }
                                    list.addAll(getListData());
                                }
                                MyApp.currExploration.setLocation_way(jsonObject.getString("location_way"));
                                if (jsonObject.getString(MString.codeset_id) != null && jsonObject.getString(MString.codeset_name) != null) {
                                    MyApp.codeSetBean = new CodeSetBean();
                                    if (!type.equals(MString.code_zero)) {
                                        MyApp.codeSetBean.setCodeset_id(jsonObject.getString(MString.codeset_id));
                                        MyApp.codeSetBean.setName(jsonObject.getString(MString.codeset_name));
                                        try {
                                            MyApp.codeSetBean.setNumber(jsonObject.getString(MString.codeset_number));
                                        } catch (Exception e) {
                                        }
                                    } else {
                                        MyApp.codeSetBean.setCodeset_id("");
                                        MyApp.codeSetBean.setName("");
                                        try {
                                            MyApp.codeSetBean.setNumber("");
                                        } catch (Exception e) {
                                        }
                                    }
                                }
                                String voltage_grade = "";
                                try {
                                    voltage_grade = jsonObject.getString(MString.voltage_grade);
                                } catch (Exception e) {
                                    voltage_grade = "";
                                }
                                for (SetPointInfItemBean s : list) {
                                    String nameCode = s.getNameCode();
                                    if (nameCode != null && nameCode.equals(MString.voltage_grade)) {
                                        MyApp.voltage_grade = jsonObject.getString(MString.voltage_grade);
                                    }
                                    if (nameCode == null || s.getItemStyle() == Constant.LatStyle) {
                                        if (!type.equals("0")) {
                                            s.setLat(Double.parseDouble(jsonObject.getString(MString.lat)));
                                            s.setLon(Double.parseDouble(jsonObject.getString(MString.lng)));
                                            currtlat = Double.parseDouble(jsonObject.getString(MString.lat));
                                            currtlon = Double.parseDouble(jsonObject.getString(MString.lng));
                                            s.setAltitude(jsonObject.getString(MString.alt));
                                        }
                                    } else if (nameCode.equals(MString.before_exp)) {
                                        if (!type.equals("0")) {
                                            String before_exp = jsonObject.getString(s.getNameCode());
                                            String before_number = jsonObject.getString(MString.before_number);
                                            if (before_exp != null) {
                                                s.setValueCode(before_exp);
                                                s.setValue(before_number);
                                            } else {
                                                s.setValueCode("");
                                                s.setValue("");
                                            }
                                        }
                                    } else if (nameCode.equals(MString.corner) && s.getItemStyle() == Constant.ButtonStyle) {
                                        if (!type.equals("0")) {
                                            if (jsonObject.getString(MString.before_corner) != null) {
                                                s.setValue(jsonObject.getString(MString.before_corner));
                                            } else {
                                                s.setValue("");
                                            }
                                        } else {
                                            paiziFlag = true;
                                        }
                                    } else if (jsonObject.getString(s.getNameCode()) != null) {
                                        if (s.getItemStyle() == Constant.EdStyle || s.getItemStyle() == Constant.dialogstyle) {
                                            if (!type.equals("0")) {
                                                if (nameCode.equals(MString.number)) {
                                                    MyApp.currExploration.setNumber(jsonObject.getString(s.getNameCode()));
                                                }
                                                s.setValue(jsonObject.getString(s.getNameCode()));
                                                s.setValueCode(jsonObject.getString(s.getNameCode()));
                                            } else if (nameCode.equals(MString.number)) {

                                            } else {
                                                s.setValue(jsonObject.getString(s.getNameCode()));
                                                s.setValueCode(jsonObject.getString(s.getNameCode()));
                                            }
                                        } else if (s.getItemStyle() == Constant.ChoiceStyle) {
                                            String code = jsonObject.getString(s.getNameCode());
                                            s.setValueCode(code);
                                            if (s.data != null && s.data.size() > 0) {
                                                for (SystemTypeBean systemTypeBean : s.data) {
                                                    if (systemTypeBean.getTypecode().equals(code)) {
                                                        s.setValue(systemTypeBean.getTypename());
                                                    }
                                                }
                                            }
                                        }

                                    } else if (jsonObject.getString(s.getNameCode()) == null && pt != null) {
                                        if (nameCode.equals(MString.user_name)) {
                                            if (!type.equals("0")) {
                                                try {
                                                    s.setValueCode(pt.getString(MString.all_user));
                                                    s.setValue(pt.getString(s.getNameCode()));
                                                } catch (Exception e) {
                                                }
                                            } else {
                                                s.setValueCode("");
                                                s.setValue("");
                                            }
                                        } else if (nameCode.equals(MString.user_num)) {
                                            if (!type.equals("0")) {
                                                s.setValue(pt.getString(s.getNameCode()));
                                                s.setValueCode(pt.getString(s.getNameCode()));
                                            } else {
                                                s.setValueCode("");
                                                s.setValue("");
                                            }
                                        } else if (nameCode.equals(MString.laxian)) {
                                            s.setValue(pt.getString(s.getNameCode()));
                                            s.setValueCode(pt.getString(s.getNameCode()));
                                        } else if (s.getItemStyle() == Constant.EdStyle) {
                                            s.setValue(pt.getString(s.getNameCode()));
                                            s.setValueCode(pt.getString(s.getNameCode()));
                                        } else if (nameCode.equals(MString.wire_times) || nameCode.equals(MString.wire_model) || nameCode.equals(MString.wire_type)) {
                                            if (voltage_grade.length() > 0) {
                                                String head = "";
                                                if (voltage_grade.equals(MString.highVoltage)) {
                                                    head = "high_" + nameCode;
                                                } else {
                                                    head = "low_" + nameCode;
                                                }

                                                String code = pt.getString(head);
                                                s.setValueCode(code);
                                                if (s.data != null && s.data.size() > 0) {
                                                    for (SystemTypeBean systemTypeBean : s.data) {
                                                        if (systemTypeBean.getTypecode().equals(code)) {
                                                            s.setValue(systemTypeBean.getTypename());
                                                        }
                                                    }
                                                }
                                            }

                                        } else if (s.getItemStyle() == Constant.ChoiceStyle) {

                                            if (nameCode.equals(MString.is_common)) {
                                                if (pt.getBoolean(s.getNameCode()) && !type.equals("0")) {
                                                    s.setValueCode(MString.YES_code);
                                                    s.setValue(MString.YES_);
                                                } else {
                                                    s.setValueCode(MString.NO_code);
                                                    s.setValue(MString.NO_);
                                                }

                                            } else {
                                                if (pt != null) {
                                                    String code = pt.getString(s.getNameCode());
                                                    s.setValueCode(code);
                                                    if (s.data != null && s.data.size() > 0) {
                                                        for (SystemTypeBean systemTypeBean : s.data) {
                                                            if (systemTypeBean.getTypecode().equals(code)) {
                                                                s.setValue(systemTypeBean.getTypename());
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                        } else if (s.getItemStyle() == Constant.ScanStyle && pt != null) {
                                            s.setValue(pt.getString(nameCode));
                                            s.setValueCode(pt.getString(nameCode));
                                        }
                                    }

                                    if (type.equals("0")) {
                                        if (nameCode != null && nameCode.equals(MString.name)) {
                                            s.setValue("");
                                            s.setValueCode("");
                                        }
                                    }
                                }
                                //手动补上档距显示
                                for (SetPointInfItemBean bean : list) {
                                    if (bean.getName().equals("档距")) {
                                        if (isNewAdd) {
                                            bean.setValue(MyApp.currExploration.getDistance());
                                            bean.setValueCode(MyApp.currExploration.getDistance());
                                        } else {
                                            if (pt != null && pt.containsKey(MString.span)) {
                                                bean.setValue(pt.getString(MString.span));
                                                bean.setValueCode(pt.getString(MString.span));
                                            } else {
                                                if (jsonObject.containsKey(MString.distance)) {
                                                    bean.setValue(jsonObject.getString(MString.distance));
                                                    bean.setValueCode(jsonObject.getString(MString.distance));
                                                } else {
                                                    bean.setValue("");
                                                    bean.setValueCode("");
                                                }
                                            }
                                        }
                                    }
                                }
                                if (type.equals("0") && paiziFlag && !MyApp.isOnLine) {
                                    getPaizi();
                                }
                                if (adapter == null) {
                                    adapter = new SetPointInformationAdapter(list, mActivity);
                                    setpoint_attribute.setAdapter(adapter);
                                } else {
                                    //由于服务器返回数据没有档距，则手动设置档距
                                    adapter.notifyDataSetChanged();
                                }
                                MyLog.L(MString.SUCCESSED + " list=" + JSON.toJSONString(list));
                                MyLog.L(MString.SUCCESSED + "解析start= " + msg.obj);
                            }
                        }
                        break;
                    case 1:

                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(mActivity, (String) msg.obj);
                        break;

                }
            }
        };
    }

    /**
     * 创建接收器*
     */
    List<Exploration> point;


    private void addPointHandler() {
        pointHandler = new Handler() {
            public boolean isfirst = true;

            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            MyDialog.Loading(mActivity);
                            if (data == null) {
                                data = FastJsonUtil.JsonToGetExplorationList((String) msg.obj);
                            } else {
                                data.clear();
                                data.addAll(FastJsonUtil.JsonToGetExplorationList((String) msg.obj));
                            }
                            SetFileUtil.setExplorationList((String) msg.obj, projectType);
                            pointHandler.sendEmptyMessage(4);

                        } else {
                            ToastShow.showShort(mActivity, MString.EXCEPTION);
                        }
                        break;
                    case 2://加载点位
                        addPoint();
                        if (MyApp.currExploration.getPt_id().length() != 0) {
                            gethandler();
                        }
                        pointHandler.sendEmptyMessage(3);
                        break;
                    case 3:
                        if (type.equals("0") && MyApp.currExploration.getPt_type().equals(Constant.LOCALPOINT)) {
                            LatLng latLng = getLatLng();
                            if (MyApp.isOnLine) {
                                MyApp.HTTP.getexpCorner(cornerHandler, HttpStringUtil.SUCCESSED, latLng, before_exp_id, type);//获取转角
                            } else {
                                getPaizi();
                            }
                        }
                        break;
                    case 4:
                        if (isfirst) {
                            getNumber();
                            if (!(type.equals("0"))) {
                                //修改点位信息
                                isfirst = false;
                            } else if (currCommon.size() > 0) {

                            }
                        } else {
                            if (point == null) point = new ArrayList<>();
                            point.clear();
                            for (Exploration b : data) {
                                if (b.pt_type.equals(Constant.LOCALPOINT)) {//过滤特征点
                                    point.add(b);//加载定位点
                                }
                            }
                            MyDialog.Close();
                            pointHandler.sendEmptyMessage(2);

                        }
                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(mActivity, (String) msg.obj);
                        break;

                }
            }
        };
    }


    /**
     * 加载点位并画出线段*
     */
    boolean flag = true;
    Map<String, Integer> map;

    private void addPoint() {
        mBaiduMap.clear();
        if (type.equals(MString.code_zero)) {
            baidumapstyle.addMarkacrcle(currentPt, MyApp.currExploration.getIcon());
        }
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder().target(currentPt).zoom(MyApp.zoom).build()));
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(currentPt));//将位置设为中心点
        points.clear();
        baidumapstyle.clearmarker_Seconds();
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (map == null) map = DataUtil.getIconData(0);
                for (Exploration exploration : point) {
                    if (exploration.lat != null && exploration.lng != null && exploration.lat.length() > 0 && exploration.lng.length() > 0) {
                        LatLng p = new LatLng(Double.parseDouble(exploration.lat), Double.parseDouble(exploration.lng));
                        baidumapstyle.addMarka(exploration, mActivity, p, Integer.parseInt(map.get(exploration.pt_id).toString()));

                        if (exploration.before_lat != null && exploration.before_lng != null && exploration.before_lat.length() > 0 && exploration.before_lng.length() > 0) {
                            LatLng p1 = new LatLng(Double.parseDouble(exploration.lat), Double.parseDouble(exploration.lng));
                            LatLng p2 = new LatLng(Double.parseDouble(exploration.before_lat), Double.parseDouble(exploration.before_lng));
                            points.add(new SpanBean(new LatLng((p1.latitude + p2.latitude) / 2, (p1.longitude + p2.longitude) / 2), exploration.distance));
                            List<LatLng> points = new ArrayList<LatLng>();
                            points.add(p1);
                            points.add(p2);
                            OverlayOptions ooPolyline = new PolylineOptions().width(10)
                                    .color(R.color.red).points(points);
                            mBaiduMap.addOverlay(ooPolyline);
                        }

                    }
                }
                //临时存储
                MyApp.explorationList.clear();
                MyApp.explorationList.addAll(point);
            }
        }).start();

    }


    boolean isaddbeforedata = true;
    List<Exploration> currCommon = new ArrayList<>();
    List<SpanBean> points = new ArrayList<>();//点位线段集合

    private void getNumber() {
        /**筛选特征点并得到编号**/
        point = new ArrayList<>();//有效点位集合
        if (isaddbeforedata) {
            before_expData = new ArrayList<>();//上联数据
            before_expData.add(new SystemTypeBean("", "无上联", new Exploration()));
        }
        currCommon.clear();
        Map<String, SystemTypeBean> map = DataUtil.getMapNumberData();
        head = map.get(MyApp.currExploration.getPt_id()).name;
        for (Exploration b : data) {
            guolv(b);
        }
        before_exp = "无上联";
        before_exp_id = "";
        if (isaddbeforedata) {
            for (SystemTypeBean datum : before_expData) {
                if (datum.data != null) {
                    String person = datum.data.getExploration_person();
                    if (person != null && person.equals(MyApp.userInfo.getUser_id())) {
                        before_exp = datum.getTypename();
                        before_exp_id = datum.getTypecode();
                        break;
                    }
                }
            }
        }
        pointHandler.sendEmptyMessage(2);
        if (list != null) {
            list.clear();
            list.addAll(getListData());//重新生成适配数据源
        }
        adapter.notifyDataSetChanged();
        if (isaddbeforedata && exploration_id.length() == 0 && exploration_uuid.length() == 0) {
            getPointNumber();//获取编号
        }
        isaddbeforedata = false;
        MyDialog.Close();
        if ((!(type.equals("0")))) {
            //修改点位信息
            getExplorationInfo(MyApp.currExploration);
        } else if (currCommon.size() > 0) {
            //新建点位
            getExplorationInfo(currCommon.get(0));//复用上一次数据
        }
//        }


    }

    private void guolv(Exploration b) {
        if (b.pt_type != null && b.pt_type.equals(Constant.LOCALPOINT) && !b.getFlag().equals(MString.del)) {//过滤特征点
            if (isaddbeforedata && !MString.getValueId(b.getExploration_id(), b.getUuid()).equals(MString.getValueId(MyApp.currExploration.getExploration_id(), MyApp.currExploration.getUuid()))) {
                if (b.exploration_id.equals(MString.code_null)) {
                    before_expData.add(new SystemTypeBean(b.uuid, b.number, b));//加载上联选项数据源
                } else {
                    before_expData.add(new SystemTypeBean(b.exploration_id, b.number, b));//加载上联选项数据源
                }
            }
            if (currCommon.size() == 0 && type.equals("0") && b.getPt_id().equals(MyApp.currExploration.getPt_id())) {

                String staid = DataFactory.getStatid(head);
                String uuid = DataFactory.getUUID(head);
                if (b.getExploration_id().length() > 0 && !b.getExploration_id().equals(MString.code_one) && b.getUuid().length() > 0) {

                    if (b.getExploration_id().equals(staid) || b.getExploration_id().equals(uuid)) {
                        currCommon.clear();
                        currCommon.add(b);//遍历与当前点位相同类型的点(点位信息重用数据集合)
                    }
                    if (b.getUuid().equals(staid) || b.getUuid().equals(uuid)) {
                        currCommon.clear();
                        currCommon.add(b);//遍历与当前点位相同类型的点(点位信息重用数据集合)
                    }
                } else if (b.getExploration_id().length() > 0 && !b.getExploration_id().equals(MString.code_one)) {
                    if (b.getExploration_id().equals(staid) || b.getExploration_id().equals(uuid)) {
                        currCommon.clear();
                        currCommon.add(b);//遍历与当前点位相同类型的点(点位信息重用数据集合)
                    }
                } else if (b.getUuid().length() > 0) {
                    if (b.getUuid().equals(staid) || b.getUuid().equals(uuid)) {
                        currCommon.clear();
                        currCommon.add(b);//遍历与当前点位相同类型的点(点位信息重用数据集合)
                    }
                }

            }
            point.add(b);//加载定位点
        }
    }

    /**
     * 获取点位编号*
     */
    private void getPointNumber() {
        addGetNewNumHandler();
        if (MyApp.currExploration.getExploration_id().length() == 0) {
            pt_id = MyApp.currExploration.getPt_id();
            setNumber();
//            }
        }
    }

    private Handler lastHandler;

    Exploration lastPoint;

    boolean isNewAdd = true;

    private void addLastHandler() {
        lastHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            lastPoint = FastJsonUtil.JsonToGetLatsExplorInfo((String) msg.obj);
                            if (lastPoint != null) {

                                lastHandler.sendEmptyMessage(1);
                            } else {
                                lastHandler.sendEmptyMessage(2);
                            }

                        } else {
                            ToastShow.showShort(MyApp.activity, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                            lastHandler.sendEmptyMessage(2);
                        }
                        break;
                    case 1:
                        if (isaddbeforedata && lastPoint != null && lastPoint.getExploration_type().equals(MyApp.currExploration.getExploration_type())) {
                            before_exp = lastPoint.getNumber();
                            before_exp_id = lastPoint.getExploration_id();
                        }
                        pointHandler.sendEmptyMessage(2);
                        if (list != null) {
                            list.clear();
                            list.addAll(getListData());//重新生成适配数据源
                        }
                        adapter.notifyDataSetChanged();
                        if (isaddbeforedata && exploration_id.length() == 0 && exploration_uuid.length() == 0) {
                            getPointNumber();//获取编号
                        }
                        isaddbeforedata = false;
                        MyDialog.Close();
                        if ((!(type.equals("0")))) {
                            //修改点位信息
                            getExplorationInfo(MyApp.currExploration);
                            isNewAdd = false;
                        } else if (currCommon.size() > 0) {
                            //新建点位
                            getExplorationInfo(currCommon.get(0));//复用上一次数据
                            isNewAdd = true;
                        }
                        break;
                    case 2:
                        /**上联标记数据**/
                        if (isaddbeforedata && before_expData.size() >= 1) {
                            before_exp = before_expData.get(0).getTypename();
                            before_exp_id = before_expData.get(0).getTypecode();
                        }
                        lastHandler.sendEmptyMessage(1);
                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(MyApp.activity, (String) msg.obj);
                        lastHandler.sendEmptyMessage(2);
                        break;
                }
            }
        };
    }

    private void setNumber() {
        Map<String, SystemTypeBean> map = DataUtil.getMapNumberData();

        SystemTypeBean bean = map.get(pt_id);
        MyLog.L(MString.SUCCESSED + "  bean.name=" + bean.name);
        NUMBER = checkNumBer(bean.name);
        MyLog.L(MString.SUCCESSED + "  NUMBER=" + NUMBER);
        getNewNumHandler.sendEmptyMessage(1);

    }

    String head = "";

    private String checkNumBer(String head) {
        this.head = head;
        List<Exploration> list = new ArrayList<>();
        for (Exploration b : point) {
            if (b.pt_type.equals(Constant.LOCALPOINT) && b.getNumber().contains(head)) {//过滤特征点与同类点
                list.add(b);
            }
        }
        String num = head + "-" + 1;
        if (list.size() > 0) {
            num = head + "-" + list.size();
            String number = DataFactory.getAddNumber(head);
            MyLog.L(MString.SUCCESSED + "ducong:get number=" + number);
            String newNum = StringUtil.getNumber(number);
            if (newNum != null) {
                num = newNum;
            }

        }
        return num;
    }

    private void addGetNewNumHandler() {
        getNewNumHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            NUMBER = JSON.parseObject((String) msg.obj).getString("newNum");
                            getNewNumHandler.sendEmptyMessage(1);
                        } else {
                            ToastShow.showShort(mActivity, "获取编号失败！");
                        }
                        break;
                    case 1:
                        MyApp.currExploration.setNumber(NUMBER);
                        if (list != null) {
                            for (SetPointInfItemBean b : list) {
                                if (b.getNameCode() != null && b.getNameCode().equals(MString.number)) {
                                    b.setValue(NUMBER);
                                    b.setValueCode(NUMBER);
                                    break;
                                }
                            }

                        }
                        adapter.notifyDataSetChanged();
                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(mActivity, (String) msg.obj);
                        break;

                }
            }
        };
    }

    /**
     * 直接完成handler*
     */
    private void addFinishHandler() {
        finishHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            AddExplorationBean explorationBean = FastJsonUtil.JsonToGetAddExploration_Id((String) msg.obj);
                            MyApp.currExploration.setBeanToHas(MyApp.currparmsExploration);
                            MyApp.currparmsExploration.clear();
                            MyApp.currExploration.setExploration_id(explorationBean.exploration_id);
                            MyApp.currExploration.setId(explorationBean.id);
                            create_SaveAndUpdate(explorationBean.exploration_id, explorationBean.id);
                            ShardPreferencesTool.saveshare(MyApp.activity, DataFactory.getId(MString.getValueId(MyApp.currProject.getStage_id(), MyApp.currProject.getUUID())) + head + "_id", explorationBean.exploration_id + "");
                            onBackPressed();
                            MyApp.activity.finish();
                        } else {
                            ToastShow.showShort(mActivity, "数据输入有误,请确认后重试！");
                        }
                        closeDialog();
                        break;
                    case HttpStringUtil.ERROR:
                        closeDialog();
                        ToastShow.showShort(mActivity, (String) msg.obj);
                        break;
                    case 1://进入验收记录界面
                        closeDialog();
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            AddExplorationBean explorationBean = FastJsonUtil.JsonToGetAddExploration_Id((String) msg.obj);
                            MyApp.currExploration.setBeanToHas(MyApp.currparmsExploration);
                            MyApp.currparmsExploration.clear();
                            MyApp.currExploration.setExploration_id(explorationBean.exploration_id);
                            MyApp.currExploration.setId(explorationBean.id);
                            create_SaveAndUpdate(explorationBean.exploration_id, explorationBean.id);
                            ShardPreferencesTool.saveshare(MyApp.activity, DataFactory.getId(MString.getValueId(MyApp.currProject.getStage_id(), MyApp.currProject.getUUID())) + head + "_id", explorationBean.exploration_id + "");
                            exploration_id = MyApp.currExploration.getExploration_id();
                            exploration_uuid = MyApp.currExploration.getUuid();
                            intent2ys();
                        } else {
                            ToastShow.showShort(mActivity, "数据输入有误,请确认后重试！");
                        }
                        break;
                }
            }
        };
    }

    /**
     * 继续设计handler*
     */
    public int tag = 0;

    private void addContinueHandler() {
        ContinueHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        //{"exploration_id":152,"id":"10"}
                        String s = FastJsonUtil.JsonToCheck_String((String) msg.obj);
                        if (s.equals(MString.TRUE) || s.equals(MString.FALSE)) {
                            AddExplorationBean explorationBean = FastJsonUtil.JsonToGetAddExploration_Id((String) msg.obj);
                            MyApp.currExploration.setBeanToHas(MyApp.currparmsExploration);
                            MyApp.currparmsExploration.clear();
                            MyApp.currExploration.setExploration_id(explorationBean.exploration_id);
                            MyApp.currExploration.setId(explorationBean.id);
                            create_SaveAndUpdate(explorationBean.exploration_id, explorationBean.id);
                            ShardPreferencesTool.saveshare(MyApp.activity, DataFactory.getId(MString.getValueId(MyApp.currProject.getStage_id(), MyApp.currProject.getUUID())) + head + "_id", explorationBean.exploration_id + "");
                            ContinueHandler.sendEmptyMessage(4);
                        } else {
                            ToastShow.showShort(mActivity, "数据输入有误,请确认后重试!");
                        }
                        closeDialog();
                        break;
                    case 1:
                        //继续操作跳转
                        tag = 1;
                        if (!MyApp.ReadOnly) {
                            ContinueHandler.sendEmptyMessage(3);
                        } else {
                            ContinueHandler.sendEmptyMessage(4);
                        }

                        break;
                    case 2:
                        //继续操作跳转
                        tag = 2;
                        if (!MyApp.ReadOnly) {
                            ContinueHandler.sendEmptyMessage(3);
                        } else {
                            ContinueHandler.sendEmptyMessage(4);
                        }

                        break;
                    case 3:
                        choiceHttp();
                        break;
                    case 4:
                        if (tag == 1) {
                            ListenerSet.getDesignClickListener(SetPointInformationActivity.this);
                        } else if (tag == 2) {
                            //跳转到拍照界面
                            IntentToActivity.intent(SetPointInformationActivity.this, PhotoGraphActivity.class);
                        } else if (tag == 3) {
                            Intent intent = new Intent(SetPointInformationActivity.this, BjListActivity.class);
                            startActivity(intent);
                        } else {
                            return;
                        }
//                        SetPointInformationActivity.this.finish();
                        break;
                    case HttpStringUtil.ERROR:
                        closeDialog();
                        ToastShow.showShort(mActivity, (String) msg.obj);
                        //ContinueHandler.sendEmptyMessage(4);
                        break;

                }
            }
        };
    }

    /**
     * 保存设置handler*
     */
    private void addUpdateHandler() {
        updateHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        String s = FastJsonUtil.JsonToCheck_String((String) msg.obj);
                        if (!s.equals(MString.TRUE)) {
                            ToastShow.showShort(mActivity, s);
                        }
                        setOnLineUpdate();
                        updateHandler.sendEmptyMessage(1);

                        break;
                    case 1:
                        if (tag == 1) {//离线点位：材料处理
                            ListenerSet.getDesignClickListener(SetPointInformationActivity.this);
                        } else if (tag == 2) {
                            IntentToActivity.intent(SetPointInformationActivity.this, PhotoGraphActivity.class);//跳转到拍照界面
                        } else if (tag == 3) {
                            Intent intent = new Intent(SetPointInformationActivity.this, BjListActivity.class);
                            startActivity(intent);
                        } else {
                            if (iscontinue) {
                                IntentToActivity.intent(SetPointInformationActivity.this, PhotoGraphActivity.class);//跳转到拍照界面
                            } else {
                                onBackPressed();
                            }
                        }
//                        MyApp.activity.finish();
                        break;
                    case HttpStringUtil.ERROR:
                        if (!MyApp.NetWorkConnect) {
                            updateHandler.sendEmptyMessage(1);
                        }
                        break;
                }
            }
        };
    }

    /**
     * ********************************网络请求接收器*************************************************************************
     */

    @Override
    protected void onResume() {
        MyApp.activity = this;
        mActivity = this;
        tag = 0;
        if (baidumapstyle != null) baidumapstyle.onResume();
        super.onResume();
    }

    /**
     * 设置地图的放大缩小按钮*
     */
    private void findViewAndInit_MapButton() {
        map_style = findViewById(R.id.map_style);
        baidumapstyle = (MBaiduMap) findViewById(R.id.baidumapstyle);
        baidumapstyle.setIsNewBlude();
        baidumapstyle.setPositionClick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (currentPt != null)
                    mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(currentPt));//将位置设为中心点
            }
        });
        /***右上方拆旧**/
        mMapView = baidumapstyle.getMapView();
        mBaiduMap = baidumapstyle.getBaiduMap();
        if (currentPt == null || currentPt.latitude == 0 || currentPt.longitude == 0 || MyApp.currExploration.getIcon() == 0)
            return;
        if (type.equals(MString.code_zero)) {
            baidumapstyle.setMarka(currentPt, MyApp.currExploration.getIcon());
        }
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder().target(currentPt).zoom(MyApp.zoom).build()));
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(currentPt));//将位置设为中心点
    }

    /**
     * 显示与隐藏按钮*
     */
    public void disPlay(View view) {
        RelativeLayout setpoint_inf_item = (RelativeLayout) findViewById(R.id.setpoint_inf_item);
        if (setpoint_inf_item.getVisibility() == View.VISIBLE) {
            setpoint_inf_item.setVisibility(View.GONE);
            ((SimpleDraweeView) view).setImageURI(UriUtil.getUri(MString.LOCALIMAGEHEAD + R.mipmap.fold));
        } else {
            setpoint_inf_item.setVisibility(View.VISIBLE);
            ((SimpleDraweeView) view).setImageURI(UriUtil.getUri(MString.LOCALIMAGEHEAD + R.mipmap.unfold));
        }
    }

    /**
     * 更新数据*
     */
    public static void setValue(String code, Object data) {
        if (data == null) return;
        if (code.equals(MString.ChoiceModelData)) {
            adapter.getData().get(adapter.mposition).setValue(((List<CodeSetBean>) data).get(0).getName());
            adapter.getData().get(adapter.mposition).setValueCode(((List<CodeSetBean>) data).get(0).getCodeset_id());

        } else {

        }
        adapter.notifyDataSetChanged();
    }

    /**
     * 更新数据*
     */
    public static double currtlat = -1;
    public static double currtlon = -1;

    public static void setValue(LatLng currentPt, String id) {
        try {
            if (currentPt == null) return;
            adapter.getData().get(0).setLat(currentPt.latitude);
            adapter.getData().get(0).setLon(currentPt.longitude);
            adapter.getData().get(0).setValueid(id);
            adapter.notifyDataSetChanged();
        } catch (Exception e) {
        }

    }

    public static void setValue() {
        try {
            if (currtlat > 0 && currtlon > 0) {
                adapter.getData().get(0).setLat(currtlat);
                adapter.getData().get(0).setLon(currtlon);
                adapter.notifyDataSetChanged();
            }
        } catch (Exception e) {
        }

    }

    public void setUpdateva() {
        if (adapter != null) {
            for (SetPointInfItemBean s : adapter.getData()) {
                if (s.getNameCode() != null && (s.getNameCode().equals(MString.wire_model) || s.getNameCode().equals(MString.wire_id))) {
                    s.setValue("");
                    s.setValueCode("");
                    break;
                }
            }
            adapter.notifyDataSetChanged();
        }
    }

    public static String projectType = "11";

    boolean buldeflag = true;

    public void isnewlyBuild(View v) {
        if (buldeflag) {
            //新建
            buldeflag = false;
            projectType = "11";
        } else {
            //拆旧
            buldeflag = true;
            projectType = "12";
        }
        getExplorationList();
    }

    boolean span = false;
    boolean corner = false;

    //转角
    public void corner(View v) {
        if (corner) {
            corner = false;
            ((SimpleDraweeView) v).setImageURI(UriUtil.getUri(MString.LOCALIMAGEHEAD + R.mipmap.displaycorner));
            addPoint();
        } else {
            corner = true;
            ((SimpleDraweeView) v).setImageURI(UriUtil.getUri(MString.LOCALIMAGEHEAD + R.mipmap.hiddencorner));
            addPoint();
        }

    }

    //档距
    public void span(View v) {
        if (span) {
            span = false;
            ((SimpleDraweeView) v).setImageURI(UriUtil.getUri(MString.LOCALIMAGEHEAD + R.mipmap.displayspan));
            addPoint();
            MyLog.L(MString.SUCCESSED + " 档距span=" + span);
        } else {
            span = true;
            ((SimpleDraweeView) v).setImageURI(UriUtil.getUri(MString.LOCALIMAGEHEAD + R.mipmap.hiddenspan));
            addSpan();
        }
    }

    private void addSpan() {
        MyLog.L(MString.SUCCESSED + " 档距points=" + JSON.toJSONString(points));
        MyLog.L(MString.SUCCESSED + " 档距span=" + span);
        if (points.size() > 0) {
            for (SpanBean s : points) {
                if (!(s.distance == null || s.distance.length() == 0)) {
                    baidumapstyle.addMarka(mActivity, s.distance, s.point);
                }

            }
        }
    }

    private boolean setOnLineAdd() {
        //新建点位
        if (MyApp.HTTP.setExplorationOutLine(MyApp.currProject.getStage_id(), list, point)) {
            MyApp.currExploration.setBeanToHas(MyApp.currparmsExploration);
            MyApp.currparmsExploration.clear();
            MyApp.currExploration.setExploration_id(MString.code_null);
            String uuid = MString.getMyUUID();
            MyApp.currExploration.setUuid(uuid);
            ShardPreferencesTool.saveshare(MyApp.activity, DataFactory.getId(MString.getValueId(MyApp.currProject.getStage_id(), MyApp.currProject.getUUID())) + head + "_id", uuid);

            String id = MString.getMyUUID();
            MyApp.currExploration.setId(MString.code_null);
            MyApp.currExploration.setPt_objectid(id);
            if (MyApp.currProject.getCurrent_schedule().equals("11")) {
                PostParams.map.put(MString.classify, MString.code_one);
            } else {
                PostParams.map.put(MString.classify, MString.code_two);
            }
            MyApp.currExploration.setExploration_person(MyApp.userInfo.getUser_id());
            PostParams.map.put(MString.exploration_person, MyApp.userInfo.getUser_id());
            create_SaveAndUpdate();
            return true;
        }
        return false;
    }

    private boolean setOnLineUpdate() {
        MyApp.currparmsExploration.clear();
        MyApp.currparmsExploration.setBeanToHas(MyApp.currExploration);
        if (MyApp.HTTP.setExplorationOutLine(MyApp.currProject.getStage_id(), list, point)) {
            MyApp.currExploration.setBeanToHas(MyApp.currparmsExploration);
            MyApp.currparmsExploration.clear();
            if (MyApp.currExploration.getExploration_person() == null
                    || MyApp.currExploration.getExploration_person().length() == 0) {
                MyApp.currExploration.setExploration_person(MyApp.userInfo.getUser_id());
                PostParams.map.put(MString.exploration_person, MyApp.userInfo.getUser_id());
            } else {
                PostParams.map.put(MString.exploration_person, MyApp.currExploration.getExploration_person());
            }
            update_SaveAndUpdate();
            return true;
        }
        return false;
    }

    /**
     * 离线存储&更新*
     */
    private void create_SaveAndUpdate() {
        //保存信息
        if (PostParams.BeforeExp != null) {
            SetFileUtil.setBeforeExp(PostParams.BeforeExp);
            PostParams.BeforeExp = null;
        }
        PostParams.map.put(MString.exploration_id, MyApp.currExploration.getExploration_id());
        PostParams.map.put(MString.uuid, MyApp.currExploration.getUuid());
        PostParams.map.put(MString.flag, MString.add);
        try {
            String pt_s = (String) PostParams.map.get(MString.pt);
            if (pt_s == null) pt_s = "";
            JSONObject pt = null;
            if (pt_s.length() > 0) {
                pt = JSON.parseObject(pt_s);
            } else {
                pt = new JSONObject();
            }
            String uuid = MString.getMyUUID();
            PostParams.map.put(MString.pt_objectid, uuid);
            pt.put(MString.id, "");
            pt.put(MString.uuid, uuid);
            pt.put(MString.flag, MString.add);
            PostParams.map.put(MString.pt, pt);
        } catch (Exception e) {

        }

        MyApp.currExploration.setJsonstring(JSON.toJSONString(PostParams.map));
        String time = System.currentTimeMillis() + "";
        MyApp.currExploration.setCreate_time(time);
        PostParams.map.put(MString.create_time, time);
        MyLog.L(MString.SUCCESSED + "  set getJsonstring========================\n" + MyApp.currExploration.getJsonstring());
        SetFileUtil.setExplorationInfo(JSON.toJSONString(PostParams.map));
        //更新踏勘点列表
        List<Exploration> explorationList = GetFileUtil.getExplorationList(MyApp.currExploration.getPoint_type());
        explorationList.add(0, MyApp.currExploration);
        SetFileUtil.setExplorationList(explorationList, MyApp.currExploration.getPoint_type());
        if (MyApp.currExploration.getPt_id().equals(MString.Transformer)) {
            SetFileUtil.setTransformerLis(MyApp.currExploration, PostParams.map);
        }
        //存储到命令文件
    }

    /**
     * 在线保存
     **/
    private void create_SaveAndUpdate(String exploration_id, String id) {
        if (id == null) {
            id = "";
        }
        // MyApp.currExploration
        //保存信息
        //GetFileUtil.getExplorationInfo(e);
        if (PostParams.BeforeExp != null) {
            SetFileUtil.setBeforeExp(PostParams.BeforeExp);
            PostParams.BeforeExp = null;
        }
        PostParams.map.put(MString.exploration_id, exploration_id);
        PostParams.map.put(MString.uuid, "");
        PostParams.map.put(MString.flag, MString.add);
        try {
            String pt_s = (String) PostParams.map.get(MString.pt);
            if (pt_s == null) pt_s = "";
            JSONObject pt = null;
            if (pt_s.length() > 0) {
                pt = JSON.parseObject(pt_s);
            } else {
                pt = new JSONObject();
            }

            PostParams.map.put(MString.pt_objectid, id);
            pt.put(MString.id, id);
            pt.put(MString.uuid, "");
            pt.put(MString.flag, MString.add);
            PostParams.map.put(MString.pt, pt);
        } catch (Exception e) {

        }

        MyApp.currExploration.setJsonstring(JSON.toJSONString(PostParams.map));
        String time = System.currentTimeMillis() + "";
        MyApp.currExploration.setCreate_time(time);
        PostParams.map.put(MString.create_time, time);
        MyLog.L(MString.SUCCESSED + "  set getJsonstring========================\n" + MyApp.currExploration.getJsonstring());
        SetFileUtil.setExplorationInfo(JSON.toJSONString(PostParams.map));
        //更新踏勘点列表


        List<Exploration> explorationList = GetFileUtil.getExplorationList(MyApp.currExploration.getPoint_type());
        explorationList.add(0, MyApp.currExploration);
        SetFileUtil.setExplorationList(explorationList, MyApp.currExploration.getPoint_type());
        if (MyApp.currExploration.getPt_id().equals(MString.Transformer)) {
            SetFileUtil.setTransformerLis(MyApp.currExploration, PostParams.map);
        }
        //存储到命令文件
        //...
    }

    private void update_SaveAndUpdate() {
        if (PostParams.BeforeExp != null) {
            SetFileUtil.setBeforeExp(PostParams.BeforeExp);
            PostParams.BeforeExp = null;
        }
        JSONObject jsonObject = JSON.parseObject(MyApp.currExploration.getJsonstring());
        if (jsonObject == null) jsonObject = new JSONObject();
        JSONObject pt = JSON.parseObject(jsonObject.getString(MString.pt));
        if (pt == null) pt = new JSONObject();
        if (jsonObject == null) jsonObject = new JSONObject();

        JSONObject json = JSON.parseObject(JSON.toJSONString(PostParams.map));
        JSONObject pt2 = JSON.parseObject(json.getString(MString.pt));

        Object[] keys = json.keySet().toArray();
        Object[] keys2 = pt2.keySet().toArray();
        try {
            for (Object s : keys) {
                if (!s.equals(MString.pt)) {
                    jsonObject.put(s.toString(), json.getString(s.toString()));
                } else {
                    for (Object s2 : keys2) {
                        pt.put(s2.toString(), pt2.getString(s2.toString()));
                    }
                    jsonObject.put(MString.pt, pt);
                }
            }

        } catch (Exception e) {
        }
        try {
            String p = (String) pt.get(MString.id);
            String objectid = (String) jsonObject.get(MString.pt_objectid);
            if ((p == null || p.length() == 0) && (objectid == null || objectid.equals(MString.code_null))) {
                String uuid = MString.getMyUUID();
                jsonObject.put(MString.pt_objectid, uuid);
                pt.put(MString.id, "");
                pt.put(MString.uuid, uuid);
                pt.put(MString.flag, MString.add);
                jsonObject.put(MString.pt, pt);
            }
        } catch (Exception e) {
        }

        jsonObject.put(MString.exploration_id, MyApp.currExploration.getExploration_id());
        jsonObject.put(MString.uuid, MyApp.currExploration.getUuid());
        if (MyApp.currExploration.getExploration_id().length() == 0 || MyApp.currExploration.getExploration_id().equals(MString.code_zero)) {
            jsonObject.put(MString.flag, MString.add);
        } else {
            jsonObject.put(MString.flag, MString.up);
        }

        MyApp.currExploration.setJsonstring(JSON.toJSONString(jsonObject));

        SetFileUtil.setExplorationInfo(JSON.toJSONString(jsonObject));
        SetFileUtil.setExplorationList(MyApp.currExploration, MyApp.currExploration.getPoint_type());
        if (MyApp.currExploration.getPt_id().equals(MString.Transformer)) {
            SetFileUtil.setTransformerLis(MyApp.currExploration, PostParams.map);
        }
    }

    /**
     * 点位编号缓存更新
     **/
    private void updateSaveNumber() {
        for (SetPointInfItemBean s : list) {
            if (s.getNameCode() != null && s.getNameCode().equals(MString.number)) {
                ShardPreferencesTool.saveshare(this, DataFactory.getId(MString.getValueId(MyApp.currProject.getStage_id(), MyApp.currProject.getUUID())) + head, s.getValueCode());
                break;
            }
        }
    }

}
